/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.bicycle.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.bicycle.entity.BicycleData;
import com.jeesite.modules.bicycle.service.BicycleDataService;

/**
 * 单车Controller
 * @author 谢宇燊
 * @version 2020-03-30
 */
@Controller
@RequestMapping(value = "${adminPath}/bicycle/bicycleData")
public class BicycleDataController extends BaseController {

	@Autowired
	private BicycleDataService bicycleDataService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public BicycleData get(String id, boolean isNewRecord) {
		return bicycleDataService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("bicycle:bicycleData:view")
	@RequestMapping(value = {"list", ""})
	public String list(BicycleData bicycleData, Model model) {
		model.addAttribute("bicycleData", bicycleData);
		return "modules/bicycle/bicycleDataList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("bicycle:bicycleData:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<BicycleData> listData(BicycleData bicycleData, HttpServletRequest request, HttpServletResponse response) {
		bicycleData.setPage(new Page<>(request, response));
		Page<BicycleData> page = bicycleDataService.findPage(bicycleData);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("bicycle:bicycleData:view")
	@RequestMapping(value = "form")
	public String form(BicycleData bicycleData, Model model) {
		model.addAttribute("bicycleData", bicycleData);
		return "modules/bicycle/bicycleDataForm";
	}

	/**
	 * 保存单车
	 */
	@RequiresPermissions("bicycle:bicycleData:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated BicycleData bicycleData) {
		bicycleDataService.save(bicycleData);
		return renderResult(Global.TRUE, text("保存单车成功！"));
	}
	
	/**
	 * 删除单车
	 */
	@RequiresPermissions("bicycle:bicycleData:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(BicycleData bicycleData) {
		bicycleDataService.delete(bicycleData);
		return renderResult(Global.TRUE, text("删除单车成功！"));
	}
	
}